﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.Connection;
using System.Data;

namespace PokerClient.Commands.CommandFactories
{
	class PlayerStatHandler : IHandle
	{
		private VisualDisp.Lobby lobby;
		private Client myClient;
		private String commands;
		private DataTable db;
		public PlayerStatHandler(VisualDisp.Lobby lobby, Client myClient)
		{
			// TODO: Complete member initialization
			this.lobby = lobby;
			this.myClient = myClient;
		}

		public string work()
		{
			try
			{
				String[] temp = commands.Split('<','>');
				db = new DataTable();
				db.Columns.Add("ID");
				db.Columns.Add("User");
				db.Columns.Add("Wins");
				db.Columns.Add("Loss");
				db.Columns.Add("Ratio");
				int k = 1;
				for (int i = 1; i < temp.Length; i++)
				{
					
					if (!temp[i].Equals(""))
					{
						
						String[] temp2 = temp[i].Split(' ');
						String[] temp3 = new String[temp2.Length - 1];
						temp2[0] = (k++)+"";
					for (int j = 0; j < temp3.Length; j++)
						{

							temp3[j] = temp2[j];
						}
					this.db.Rows.Add(temp3);
					
					}
				}
					/*foreach (String s in temp)
						
					{
						if (s != "" && s != "Statistics")
						{
							db.Rows.Add(s);
						}
					}*/
					return "Success!";
			}

			catch (Exception ex)
			{
				return ex.Message;
			}
		}

		public void assignCommand(string commands)
		{
			this.commands = commands;
		}

		public void analyze()
		{
			if (this.db != null)
			{
				this.lobby.dBase = this.db;
			}
			
		}
	}
}
